package com.wonders.cyxtjsonupdate;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.wonders.cyxtjsonupdate.entity.Cyxt;
import com.wonders.cyxtjsonupdate.service.CyxtJsonData;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.text.NumberFormat;
import java.util.*;

@SpringBootTest
class CyxtJsonUpdateApplicationTests3 {

    //-----------客运机场吞吐量

    @Autowired
    CyxtJsonData cyxtJsonData;

    @Test
    void test1() {
        Calendar cal = Calendar.getInstance();
        NumberFormat nf = NumberFormat.getInstance();
        nf.setMaximumFractionDigits(0);//保留0位
        //获得当前月份
        int month = new Date().getMonth();
        month = 11;//因目前1月份数据库未产生12月份数据，此此先模拟
        //获得当前年份
        int year = cal.get(Calendar.YEAR);
        ArrayList<String> list = new ArrayList<>();//用来存储所有的最终的json
        //初始化虹桥机场吞吐量量的list
        List<Map<String, Object>> hongqiaoList = cyxtJsonData.initHongQiaoAirport();
        //初始化浦东机场吞吐量量的list
        List<Map<String, Object>> pudongList = cyxtJsonData.initPudongAirport();


        Cyxt cyxt = buildgeneralpParame("8fdb63d797524b6baa86d7b796180c64", "kyLazy", "myChart18");
        buildairPortData(cyxt,month,hongqiaoList,pudongList,list);
        System.out.println(list);

    }

    /**
     * Methad info:机场吞吐量
     * @author 陈兆庆
     * @date 2022/1/6 14:38
     */

    public void buildairPortData(Cyxt cyxt,int month,List<Map<String, Object>> hongqiaoList,List<Map<String, Object>> pudongList,List list){
        ArrayList<String>airList= new ArrayList<>();
        for (int i = 0; i < month; i++) {
            Object monthsumhq = hongqiaoList.get(i).get("MONTHSUM");
            int hongqiaoData= (int)(Double.parseDouble(monthsumhq.toString())*10000);
            Object monthsumpd = pudongList.get(i).get("MONTHSUM");
            int pudongData= (int)(Double.parseDouble(monthsumpd.toString())*10000);
            if(i==0){
                airList.add("{direction: '一月', '虹桥机场吞吐量(人次)': "+hongqiaoData+",'浦东机场吞吐量(人次)': "+pudongData+"}");
            }else if(i==1){
                airList.add("{direction: '二月', '虹桥机场吞吐量(人次)': "+hongqiaoData+",'浦东机场吞吐量(人次)': "+pudongData+"}");
            }else if(i==2){
                airList.add("{direction: '三月', '虹桥机场吞吐量(人次)': "+hongqiaoData+",'浦东机场吞吐量(人次)': "+pudongData+"}");
            }else if(i==3){
                airList.add("{direction: '四月', '虹桥机场吞吐量(人次)': "+hongqiaoData+",'浦东机场吞吐量(人次)': "+pudongData+"}");
            }else if(i==4){
                airList.add("{direction: '五月', '虹桥机场吞吐量(人次)': "+hongqiaoData+",'浦东机场吞吐量(人次)': "+pudongData+"}");
            }else if(i==5){
                airList.add("{direction: '六月', '虹桥机场吞吐量(人次)': "+hongqiaoData+",'浦东机场吞吐量(人次)': "+pudongData+"}");
            }else if(i==6){
                airList.add("{direction: '七月', '虹桥机场吞吐量(人次)': "+hongqiaoData+",'浦东机场吞吐量(人次)': "+pudongData+"}");
            }else if(i==7){
                airList.add("{direction: '八月', '虹桥机场吞吐量(人次)': "+hongqiaoData+",'浦东机场吞吐量(人次)': "+pudongData+"}");
            }else if(i==8){
                airList.add("{direction: '九月', '虹桥机场吞吐量(人次)': "+hongqiaoData+",'浦东机场吞吐量(人次)': "+pudongData+"}");
            }else if(i==9){
                airList.add("{direction: '十月', '虹桥机场吞吐量(人次)': "+hongqiaoData+",'浦东机场吞吐量(人次)': "+pudongData+"}");
            }else if(i==10){
                airList.add("{direction: '十一月', '虹桥机场吞吐量(人次)': "+hongqiaoData+",'浦东机场吞吐量(人次)': "+pudongData+"}");
            }else if(i==11){
                airList.add("{direction: '十二月', '虹桥机场吞吐量(人次)': "+hongqiaoData+",'浦东机场吞吐量(人次)': "+pudongData+"}");
            }
        }
        cyxt.setDataItem1(airList.toString());
        cyxt.setDataItem2("['direction', '虹桥机场吞吐量(人次)','浦东机场吞吐量(人次)']");
        String yjhy = JSONObject.toJSONString(cyxt, SerializerFeature.WriteMapNullValue);
        list.add(yjhy);


    }



    /**
     * Methad info:通用的参数
     * @return com.wonders.cyxtjsonupdate.entity.Cyxt
     * @author 陈兆庆
     * @date 2022/1/4 14:47
     */
    public Cyxt buildgeneralpParame(String id, String mainType, String subType) {
        Cyxt cyxt = new Cyxt();
        cyxt.setId(id);
        cyxt.setMainType(mainType);
        cyxt.setSubType(subType);
        return cyxt;
    }
}
